home *** CD-ROM | disk | FTP | other *** search
/ Ultra Pack / UltraComputing Partner Applications.iso / SunLabs / tclTK / src / tk4.0 / tests / imgPhoto.test < prev    next >
Encoding:
Text File  |  1995-06-21  |  13.8 KB  |  350 lines

  1. # This file is a Tcl script to test out the "photo" image type and the
  2. # other procedures in the file tkImgPhoto.c.  It is organized in the
  3. # standard fashion for Tcl tests.
  4. #
  5. # Copyright (c) 1994 The Australian National University
  6. # Copyright (c) 1994 Sun Microsystems, Inc.
  7. #
  8. # See the file "license.terms" for information on usage and redistribution
  9. # of this file, and for a DISCLAIMER OF ALL WARRANTIES.
  10. #
  11. # IN NO EVENT SHALL THE UNIVERSITY OF CALIFORNIA BE LIABLE TO ANY PARTY FOR
  12. # DIRECT, INDIRECT, SPECIAL, INCIDENTAL, OR CONSEQUENTIAL DAMAGES ARISING OUT
  13. # OF THE USE OF THIS SOFTWARE AND ITS DOCUMENTATION, EVEN IF THE UNIVERSITY OF
  14. # CALIFORNIA HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  15. #
  16. # THE UNIVERSITY OF CALIFORNIA SPECIFICALLY DISCLAIMS ANY WARRANTIES,
  17. # INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY
  18. # AND FITNESS FOR A PARTICULAR PURPOSE.  THE SOFTWARE PROVIDED HEREUNDER IS
  19. # ON AN "AS IS" BASIS, AND THE UNIVERSITY OF CALIFORNIA HAS NO OBLIGATION TO
  20. # PROVIDE MAINTENANCE, SUPPORT, UPDATES, ENHANCEMENTS, OR MODIFICATIONS.
  21. #
  22. # Author: Paul Mackerras (paulus@cs.anu.edu.au)
  23. #
  24. # @(#) imgPhoto.test 1.9 95/06/21 15:50:04
  25.  
  26. if {[info procs test] != "test"} {
  27.     source defs
  28. }
  29.  
  30. foreach i [winfo children .] {
  31.     destroy $i
  32. }
  33. wm geometry . {}
  34. raise .
  35.  
  36. eval image delete [image names]
  37.  
  38. canvas .c
  39. pack .c
  40. update
  41.  
  42. test imgPhoto-1.1 {options for photo images} {
  43.     image create photo p1 -width 79 -height 83
  44.     list [lindex [p1 configure -width] 4] [lindex [p1 configure -height] 4] \
  45.     [image width p1] [image height p1]
  46. } {79 83 79 83}
  47. test imgPhoto-1.2 {options for photo images} {
  48.     list [catch {image create photo p1 -file no.such.file} err] \
  49.     [string tolower $err]
  50. } {1 {couldn't read image file "no.such.file": no such file or directory}}
  51. test imgPhoto-1.3 {options for photo images} {
  52.     list [catch {image create photo p1 -file \
  53.         $tk_library/demos/images/teapot.ppm \
  54.         -format no.such.format} err] $err
  55. } {1 {image file format "no.such.format" is unknown}}
  56. test imgPhoto-1.4 {options for photo images} {
  57.     image create photo p1 -file $tk_library/demos/images/teapot.ppm
  58.     list [image width p1] [image height p1]
  59. } {256 256}
  60. test imgPhoto-1.5 {options for photo images} {
  61.     image create photo p1 -file $tk_library/demos/images/teapot.ppm \
  62.         -format ppm -width 79 -height 83
  63.     list [image width p1] [image height p1] \
  64.     [lindex [p1 configure -file] 4] [lindex [p1 configure -format] 4]
  65. } "79 83 [glob $tk_library]/demos/images/teapot.ppm ppm"
  66. test imgPhoto-1.6 {options for photo images} {
  67.     image create photo p1 -palette 2/2/2 -gamma 2.2
  68.     list [lindex [p1 configure -gamma] 4] [lindex [p1 configure -palette] 4]
  69. } {2.2 2/2/2}
  70. test imgPhoto-1.7 {options for photo images} {
  71.     list [catch {image create photo p1 -file README} err] $err
  72. } {1 {couldn't recognize data in image file "README"}}
  73. test imgPhoto-1.8 {options for photo images} {
  74.     list [catch {image create photo -blah blah} err] $err
  75. } {1 {unknown option "-blah"}}
  76.  
  77. test imgPhoto-2.1 {ImgPhotoCreate procedure} {
  78.     eval image delete [image names]
  79.     catch {image create photo -blah blah}
  80.     image names
  81. } {}
  82. test imgPhoto-2.2 {ImgPhotoCreate procedure} {
  83.     eval image delete [image names]
  84.     image create photo image1
  85.     list [info commands image1] [image names] \
  86.     [image width image1] [image height image1]
  87. } {image1 image1 0 0}
  88.  
  89. test imgPhoto-3.1 {ImgPhotoConfigureMaster procedure} {
  90.     image create photo p1 -file $tk_library/demos/images/teapot.ppm
  91.     p1 configure -file $tk_library/demos/images/teapot.ppm
  92. } {}
  93. test imgPhoto-3.2 {ImgPhotoConfigureMaster procedure} {
  94.     image create photo p1 -file $tk_library/demos/images/teapot.ppm
  95.     list [catch {p1 configure -file bogus} err] [string tolower $err] \
  96.     [image width p1] [image height p1]
  97. } {1 {couldn't read image file "bogus": no such file or directory} 256 256}
  98. test imgPhoto-3.3 {ImgPhotoConfigureMaster procedure} {
  99.     image create photo p1
  100.     .c create image 10 10 -image p1 -tags p1.1 -anchor nw
  101.     .c create image 300 10 -image p1 -tags p1.2 -anchor nw
  102.     update
  103.     p1 configure -file $tk_library/demos/images/teapot.ppm
  104.     update
  105.     list [image width p1] [image height p1] [.c bbox p1.1] [.c bbox p1.2]
  106. } {256 256 {10 10 266 266} {300 10 556 266}}
  107.  
  108. eval image delete [image names]
  109. image create photo p1
  110. .c create image 10 10 -image p1
  111. update
  112.  
  113. test imgPhoto-4.1 {ImgPhotoCmd procedure} {
  114.     list [catch {p1} err] $err
  115. } {1 {wrong # args: should be "p1 option ?arg arg ...?"}}
  116. test imgPhoto-4.2 {ImgPhotoCmd procedure} {
  117.     list [catch {p1 blah} err] $err
  118. } {1 {bad option "blah": must be blank, cget, configure, copy, get, put, read, redither, or write}}
  119. test imgPhoto-4.3 {ImgPhotoCmd procedure: blank option} {
  120.     p1 blank
  121.     list [catch {p1 blank x} err] $err
  122. } {1 {wrong # args: should be "p1 blank"}}
  123. test imgPhoto-4.4 {ImgPhotoCmd procedure: cget option} {
  124.     list [catch {p1 cget} msg] $msg
  125. } {1 {wrong # args: should be "p1 cget option"}}
  126. test imgPhoto-4.5 {ImgPhotoCmd procedure: cget option} {
  127.     image create photo p2 -width 25 -height 30
  128.     list [p2 cget -width] [p2 cget -height]
  129. } {25 30}
  130. test imgPhoto-4.6 {ImgPhotoCmd procedure: configure option} {
  131.     llength [p1 configure]
  132. } {7}
  133. test imgPhoto-4.7 {ImgPhotoCmd procedure: configure option} {
  134.     p1 conf -palette 3/4/2
  135.     p1 configure -palette
  136. } {-palette {} {} {} 3/4/2}
  137. test imgPhoto-4.8 {ImgPhotoCmd procedure: configure option} {
  138.     list [catch {p1 configure -blah} msg] $msg
  139. } {1 {unknown option "-blah"}}
  140. test imgPhoto-4.9 {ImgPhotoCmd procedure: configure option} {
  141.     list [catch {p1 configure -palette {} -gamma} msg] $msg
  142. } {1 {value for "-gamma" missing}}
  143. test imgPhoto-4.10 {ImgPhotoCmd procedure: copy option} {
  144.     image create photo p2 -file $tk_library/demos/images/teapot.ppm
  145.     p1 configure -width 0 -height 0 -palette {} -gamma 1
  146.     p1 copy p2
  147.     list [image width p1] [image height p1] [p1 get 100 100]
  148. } {256 256 {169 117 90}}
  149. test imgPhoto-4.11 {ImgPhotoCmd procedure: copy option} {
  150.     list [catch {p1 copy} msg] $msg
  151. } {1 {wrong # args: should be "p1 copy source-image ?-from x1 y1 x2 y2? ?-to x1 y1 x2 y2? ?-zoom x y? ?-subsample x y?"}}
  152. test imgPhoto-4.12 {ImgPhotoCmd procedure: copy option} {
  153.     list [catch {p1 copy blah} msg] $msg
  154. } {1 {image "blah" doesn't exist or is not a photo image}}
  155. test imgPhoto-4.13 {ImgPhotoCmd procedure: copy option} {
  156.     list [catch {p1 copy p2 -blah} msg] $msg
  157. } {1 {unrecognized option "-blah": must be -from, -shrink, -subsample, -to, or -zoom}}
  158. test imgPhoto-4.14 {ImgPhotoCmd procedure: copy option} {
  159.     list [catch {p1 copy p2 -from -to} msg] $msg
  160. } {1 {the "-from" option requires one to four integer values}}
  161. test imgPhoto-4.15 {ImgPhotoCmd procedure: copy option} {
  162.     p1 copy p2
  163.     p1 copy p2 -from 0 70 60 120 -shrink
  164.     list [image width p1] [image height p1] [p1 get 20 10]
  165. } {60 50 {215 154 120}}
  166. test imgPhoto-4.16 {ImgPhotoCmd procedure: copy option} {
  167.     p1 copy p2 -from 60 120 0 70 -to 20 50
  168.     list [image width p1] [image height p1] [p1 get 40 80]
  169. } {80 100 {19 92 192}}
  170. test imgPhoto-4.17 {ImgPhotoCmd procedure: copy option} {
  171.     p1 copy p2 -from 0 120 60 70 -to 0 0 100 100
  172.     list [image width p1] [image height p1] [p1 get 80 60]
  173. } {100 100 {215 154 120}}
  174. test imgPhoto-4.18 {ImgPhotoCmd procedure: copy option} {
  175.     p1 copy p2 -from 60 70 0 120 -zoom 2
  176.     list [image width p1] [image height p1] [p1 get 100 50]
  177. } {120 100 {169 99 47}}
  178. test imgPhoto-4.19 {ImgPhotoCmd procedure: copy option} {
  179.     p1 copy p2 -from 0 70 60 120
  180.     list [image width p1] [image height p1] [p1 get 100 50]
  181. } {120 100 {169 99 47}}
  182. test imgPhoto-4.20 {ImgPhotoCmd procedure: copy option} {
  183.     p1 copy p2 -from 20 20 200 180 -subsample 2 -shrink
  184.     list [image width p1] [image height p1] [p1 get 50 30]
  185. } {90 80 {207 146 112}}
  186. test imgPhoto-4.21 {ImgPhotoCmd procedure: copy option} {
  187.     p1 copy p2
  188.     set result [list [image width p1] [image height p1]]
  189.     p1 conf -width 49 -height 51
  190.     lappend result [image width p1] [image height p1]
  191.     p1 copy p2
  192.     lappend result [image width p1] [image height p1]
  193.     p1 copy p2 -from 0 0 10 10 -shrink
  194.     lappend result [image width p1] [image height p1]
  195.     p1 conf -width 0
  196.     p1 copy p2 -from 0 0 10 10 -shrink
  197.     lappend result [image width p1] [image height p1]
  198.     p1 conf -height 0
  199.     p1 copy p2 -from 0 0 10 10 -shrink
  200.     lappend result [image width p1] [image height p1]
  201. } {256 256 49 51 49 51 49 51 10 51 10 10}
  202. test imgPhoto-4.22 {ImgPhotoCmd procedure: get option} {
  203.     p1 read $tk_library/demos/images/teapot.ppm
  204.     list [p1 get 100 100] [p1 get 150 100] [p1 get 100 150]
  205. } {{169 117 90} {172 115 84} {35 35 35}}
  206. test imgPhoto-4.23 {ImgPhotoCmd procedure: get option} {
  207.     list [catch {p1 get 256 0} err] $err
  208. } {1 {p1 get: coordinates out of range}}
  209. test imgPhoto-4.24 {ImgPhotoCmd procedure: get option} {
  210.     list [catch {p1 get 0 -1} err] $err
  211. } {1 {p1 get: coordinates out of range}}
  212. test imgPhoto-4.25 {ImgPhotoCmd procedure: get option} {
  213.     list [catch {p1 get} err] $err
  214. } {1 {wrong # args: should be "p1 get x y"}}
  215. test imgPhoto-4.26 {ImgPhotoCmd procedure: put option} {
  216.     list [catch {p1 put} err] $err
  217. } {1 {wrong # args: should be "p1 put {{colors...}...} ?-to x1 y1 x2 y2?"}}
  218. test imgPhoto-4.27 {ImgPhotoCmd procedure: put option} {
  219.     list [catch {p1 put {{white} {white white}}} err] $err
  220. } {1 {all elements of color list must have the same number of elements}}
  221. test imgPhoto-4.28 {ImgPhotoCmd procedure: put option} {
  222.     list [catch {p1 put {{blahgle}}} err] $err
  223. } {1 {can't parse color "blahgle"}}
  224. test imgPhoto-4.29 {ImgPhotoCmd procedure: put option} {
  225.     p1 put -to 10 10 20 20 {{white}}
  226.     p1 get 19 19
  227. } {255 255 255}
  228. test imgPhoto-4.30 {ImgPhotoCmd procedure: read option} {
  229.     list [catch {p1 read} err] $err
  230. } {1 {wrong # args: should be "p1 read fileName ?-format format-name? ?-from x1 y1 x2 y2? ?-to x y? ?-shrink?"}}
  231. test imgPhoto-4.31 {ImgPhotoCmd procedure: read option} {
  232.     list [catch {p1 read $tk_library/demos/images/teapot.ppm -zoom 2} err] $err
  233. } {1 {unrecognized option "-zoom": must be -format, -from, -shrink, or -to}}
  234. test imgPhoto-4.32 {ImgPhotoCmd procedure: read option} {
  235.     list [catch {p1 read bogus} err] [string tolower $err]
  236. } {1 {couldn't read image file "bogus": no such file or directory}}
  237. test imgPhoto-4.33 {ImgPhotoCmd procedure: read option} {
  238.     list [catch {p1 read $tk_library/demos/images/teapot.ppm \
  239.         -format bogus} err] $err
  240. } {1 {image file format "bogus" is unknown}}
  241. test imgPhoto-4.34 {ImgPhotoCmd procedure: read option} {
  242.     list [catch {p1 read README} err] $err
  243. } {1 {couldn't recognize data in image file "README"}}
  244. test imgPhoto-4.35 {ImgPhotoCmd procedure: read option} {
  245.     p1 read $tk_library/demos/images/teapot.ppm -shrink
  246.     list [image width p1] [image height p1] [p1 get 120 120]
  247. } {256 256 {161 109 82}}
  248. test imgPhoto-4.36 {ImgPhotoCmd procedure: read option} {
  249.     p1 read $tk_library/demos/images/teapot.ppm -from 0 70 60 120 \
  250.         -to 10 10 -shrink
  251.     list [image width p1] [image height p1] [p1 get 29 19]
  252. } {70 60 {244 180 144}}
  253. test imgPhoto-4.37 {ImgPhotoCmd procedure: redither option} {
  254.     p1 redither
  255.     list [catch {p1 redither x} err] $err
  256. } {1 {wrong # args: should be "p1 redither"}}
  257. test imgPhoto-4.38 {ImgPhotoCmd procedure: write option} {
  258.     list [catch {p1 write} err] $err
  259. } {1 {wrong # args: should be "p1 write fileName ?-format format-name??-from x1 y1 x2 y2?"}}
  260. test imgPhoto-4.39 {ImgPhotoCmd procedure: write option} {
  261.     list [catch {p1 write teapot.tmp -format bogus} err] $err
  262. } {1 {image file format "bogus" is unknown}}
  263.  
  264. test imgPhoto-5.1 {ImgPhotoGet/Free procedures, shared instances} {
  265.     eval image delete [image names]
  266.     .c delete all
  267.     image create photo p1 -file $tk_library/demos/images/teapot.ppm
  268.     .c create image 0 0 -image p1 -tags p1.1
  269.     .c create image 256 0 -image p1 -tags p1.2
  270.     .c create image 0 256 -image p1 -tags p1.3
  271.     update
  272.     .c delete i1.1
  273.     p1 configure -width 1
  274.     update
  275.     .c delete i1.2
  276.     p1 configure -height 1
  277.     update
  278.     image delete p1
  279. } {}
  280.  
  281. test imgPhoto-6.1 {ImgPhotoDisplay procedure, blank display} {
  282.     .c delete all
  283.     image create photo p1 -width 10 -height 10
  284.     p1 blank
  285.     .c create image 10 10 -image p1
  286.     update
  287. } {}
  288.  
  289. test imgPhoto-7.1 {ImgPhotoFree procedure, resource freeing} {
  290.     eval image delete [image names]
  291.     .c delete all
  292.     image create photo p1 -file $tk_library/demos/images/teapot.ppm
  293.     .c create image 0 0 -image p1 -anchor nw
  294.     update
  295.     .c delete all
  296.     image delete p1
  297. } {}
  298. test imgPhoto-7.2 {ImgPhotoFree procedures, unlinking} {
  299.     image create photo p1 -file $tk_library/demos/images/teapot.ppm
  300.     .c create image 10 10 -image p1 -anchor nw
  301.     button .b1 -image p1
  302.     button .b2 -image p1
  303.     button .b3 -image p1
  304.     pack .b1 .b2 .b3
  305.     update
  306.     destroy .b2
  307.     update
  308.     destroy .b3
  309.     update
  310.     destroy .b1
  311.     update
  312.     .c delete all
  313. } {}
  314. test imgPhoto-7.3 {ImgPhotoFree procedures, multiple visuals} {
  315.     image create photo p1 -file $tk_library/demos/images/teapot.ppm
  316.     button .b1 -image p1
  317.     frame .f -visual best
  318.     button .f.b2 -image p1
  319.     pack .f.b2
  320.     pack .b1 .f
  321.     update
  322.     destroy .b1
  323.     update
  324.     .f.b2 configure -image {}
  325.     update
  326.     destroy .f
  327.     image delete p1
  328. } {}
  329.  
  330. test imgPhoto-8.1 {ImgPhotoDelete procedure} {
  331.     image create photo p2 -file $tk_library/demos/images/teapot.ppm
  332.     image delete p2
  333. } {}
  334. test imagePhoto-8.2 {ImgPhotoDelete procedure} {
  335.     image create photo p2 -file $tk_library/demos/images/teapot.ppm
  336.     rename p2 newp2
  337.     set x [list [info command p2] [info command new*] [newp2 cget -file]]
  338.     image delete p2
  339.     lappend x [info command new*]
  340. } "{} newp2 $tk_library/demos/images/teapot.ppm {}"
  341.  
  342. test imagePhoto-9.1 {ImgPhotoCmdDeletedProc procedure} {
  343.     image create photo p2 -file $tk_library/demos/images/teapot.ppm
  344.     rename p2 {}
  345.     list [lsearch -exact [image names] p2] [catch {p2 foo} msg] $msg
  346. } {-1 1 {invalid command name "p2"}}
  347.  
  348. destroy .c
  349. eval image delete [image names]
  350.